{% extends "zato/index.html" %}

{% block html_title %}Delivery details{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
    <link rel="stylesheet" type="text/css" href="/static/css/slideout.css">
{% endblock %}

{% block "extra_js" %}

    {% comment %} jQuery {% endcomment %}
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/pattern/delivery/look-up-task.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/pattern/delivery/details.js"></script>

{% endblock %}

{% block "content" %}
<h2 class="zato"><a href="{% url "pattern-delivery" %}?cluster={{ cluster_id }}&amp;target_type={{ item.target_type }}">Guaranteed delivery</a>{% if has_item %} : {{ item.task_id }} : {{ item.state }}{% endif %}</h2>

{% if has_item %}

    {% include "zato/user-message.html" %}

    <div id="markup">
        <table id="data-table">
            <tr>
                <td style="vertical-align:bottom">
                    {{ item.task_id }}
                </td>
                <td style="padding-bottom:0px;text-align:right">
                    {% if show_resubmit_button %}<button id="resubmit1" name="resubmit1" type="submit">Resubmit</button>{% endif %}
                    {% if show_update_button %}<button id="update1" name="update1" type="submit">Update</button>{% endif %}
                    &nbsp;|&nbsp;
                    <button id="delete1" name="delete1" type="submit">Delete</button>
                </td>
            </tr>

            <tr>
                <td colspan="2" style="padding-top:0px">
                    <hr/>
                </td>
            </tr>
            <tr>
                <td class='inline_header' colspan="2">Overview</td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="item-details-body" style="width:100%">
                        <table style="width:100%">
                            <tr>
                                <td style="width:30%">
                                    <table style="width:100%" >
                                        <tr>
                                            <td class="inline_header">Definition/target</td>
                                        </tr>
                                        <tr>
                                            <td>{{ item.def_name }}/{{ item.target }}</td>
                                        </tr>
                                        <tr>
                                            <td class="inline_header">Created/in-doubt since</td>
                                        </tr>
                                        <tr>
                                            <td>
                                                {{ item.creation_time }}
                                                <br/>
                                                {% if item.state == 'in-doubt' %}{{ item.last_used }}{% else %}<span class="form_hint">n/a</a>{% endif %}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class='inline_header'>Source/target count</td>
                                        </tr>
                                        <tr>
                                            <td>
                                                {{ item.source_count}}/{{ item.target_count }}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class='inline_header'>Check after/retry repeats/retry seconds/RS#</td>
                                        </tr>
                                        <tr>
                                            <td>
                                                {{ item.check_after }}/{{ item.retry_repeats }}/{{ item.retry_seconds }}/{{ item.resubmit_count }}
                                            </td>
                                        </tr>
                                    </table>
                                </td>

                                <td>
                                    <table style="width:100%">
                                        <tr>
                                            <td class='inline_header'>History</td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <table style="width:100%;border-spacing:2px">
                                                    <tr>
                                                        <td class="inline_header" style="width:5%">RS#</td>
                                                        <td class="inline_header" style="width:15%">TS</td>
                                                        <td class="inline_header" style="width:15%">Delta</td>
                                                        <td class="inline_header" style="width:15%">State</td>
                                                        <td class="inline_header" style="width:50%">Ctx</td>
                                                    </tr>
                                                    {% for item in history %}
                                                        <tr>
                                                            <td>{{ item.resubmit_count }}</td>
                                                            <td>{{ item.entry_time }}</td>
                                                            <td>{{ item.delta }}</td>
                                                            <td>{{ item.entry_type }}</td>
                                                            <td>{{ item.entry_ctx }}</td>
                                                        </tr>
                                                    {% endfor %}
                                                </table>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table>
                    </div> <!-- class="item-details-body" -->
                </td>
            </tr>

            <tr>
                <td class='inline_header' colspan="2">Payload - {{ item.payload_len|filesizeformat }} {% if item.payload_len > 1024 %}({{ item.payload_len }} bytes){% endif %}</td>
            </tr>
            <tr>
                <td colspan="2">
                    <textarea id="payload" style="width:100%; height:520px">{{ item.payload }}</textarea>
                </td>
            </tr>

            <tr>
                <td class='inline_header' colspan="2">Args</td>
            </tr>
            <tr>
                <td colspan="2">
                    <textarea id="args" style="width:100%; height:120px">{{ item.args }}</textarea>
                </td>
            </tr>

            <tr>
                <td class='inline_header' colspan="2">Kwargs</td>
            </tr>
            <tr>
                <td colspan="2">
                    <textarea id="kwargs" style="width:100%; height:120px">{{ item.kwargs }}</textarea>
                </td>
            </tr>

            <tr>
                <td class='inline_header' colspan="2">Payload SHA1</td>
            </tr>
            <tr>
                <td colspan="2">{{ item.payload_sha1 }}</td>
            </tr>

            <tr>
                <td class='inline_header' colspan="2">Payload SHA256</td>
            </tr>
            <tr>
                <td colspan="2">{{ item.payload_sha256 }}</td>
            </tr>

            <tr>
                <td colspan="2">
                    <hr/>
                </td>
            </tr>

            <tr>
                <td style="text-align:right;padding-top:0px" colspan="2">
                    {% if show_resubmit_button %}<button id="resubmit1" name="resubmit1" type="submit">Resubmit</button>{% endif %}
                    {% if show_update_button %}<button id="update2" name="update2" type="submit">Update</button>{% endif %}
                    &nbsp;|&nbsp;
                    <button id="delete2" name="delete2" type="submit">Delete</button>
                </td>
            </tr>

        </table>
    </div>

    <input type="hidden" name="task_id" id="task_id" value="{{ item.task_id }}" />

{% else %}

    <div id="user-message-div">
        <pre id="user-message" class="user-message user-message-failure">No such task [{{ req.zato.args.task_id }}]</pre>
    </div>

{% endif %} {% comment %}has_item{% endcomment %}

<input type="hidden" name="cluster_id" id="cluster_id" value="{{ cluster_id }}" />

{% include "zato/pattern/delivery/look-up-task.html" %}


{% endblock %}
